import Vue from 'vue'
import Vuex from 'vuex'
import { stat } from 'fs'
Vue.use(Vuex)
const key = 'user'
const isLogin = 'isLogin'
export default new Vuex.Store({
  state: {
    // worklist: JSON.parse(localStorage.getItem('worklist' || '[]'))
    worklist: [],
    activeinfo: 0,
    name: '马玉un',
    user: null,
    isLogin: '0'
    // isBottom: true
  },
  // getters: {
  //   getStorage: function (state) {
  //     if (!state.user) {
  //       state.user = JSON.parse(localStorage.getItem(key))
  //       state.isLogin = localStorage.getItem(isLogin)
  //     }
  //     return state.user
  //   }
  // },
  mutations: {
    worklist_list (state, obj) {
      console.log(state.worklist)
      // console.log(obj)
      var flag = false
      // state.worklist.forEach(el => {
      //   if (el.uid === obj.id) {
      //     flag = true
      //   }
      // })
      // if (!flag) {
      state.worklist.push(obj)
      state.name = obj.name
      // }
      localStorage.setItem('worklist', JSON.stringify(obj))
      // console.log(state.worklist)
    }

  },
  actions: {
    worklist_list ({ commit }, obj) {
      commit('worklist_list', obj)
      // console.log(obj)
    }

  }
})
